<?php

namespace App\Admin\Tools\ContractedCustomer;

use App\Models\FinanceIncomeModel;
use Encore\Admin\Grid\Tools\AbstractTool;

class ContractedCustomerIncomeRecordTool extends AbstractTool
{
    private int $id;

    public function __construct(int $id)
    {
        $this->id = $id;
    }

    /**
     * @inheritDoc
     */
    public function render()
    {
        return view('contractedCustomer.income_record', [
            'id' => $this->id,
            'data' => FinanceIncomeModel::query()
                ->leftJoin('admin_users', 'admin_users.id', '=', 'finance_income.audit_id')
                ->select('finance_income.*', 'admin_users.name')
                ->where('contracted_customer_id', $this->id)
                ->where('finance_income.status', 1)
                ->get()->toArray()
        ]);
    }
}
